package com.fa7.android.example.listafacil;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class AddCategoriaActivity extends Activity {
	private Button mAddCompraButton;
	private EditText mNameEdit;
	private EditText mDescriptionEdit;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.add_categoria_layout);
		
		mAddCompraButton = (Button)findViewById(R.id.add_button);
		mNameEdit = (EditText)findViewById(R.id.add_name);
		mDescriptionEdit = (EditText)findViewById(R.id.add_description);
		
		mAddCompraButton.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) {
				Categoria cat = new Categoria(null,mNameEdit.getText().toString(),mDescriptionEdit.getText().toString());
				CategoriaDB categoriaDB = new CategoriaDB(getApplicationContext());
				categoriaDB.insert(cat);
				
				finish();
			}
		});
	}
	
	@Override
	protected void onDestroy() {
		Toast.makeText(getApplicationContext(), "Categoria Adicionada com Sucesso", Toast.LENGTH_LONG).show();
		super.onDestroy();
	}
	
}
